﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace BookManagement
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //分别从前台获取用户输入的数据
            string name = this.txtName.Text;
            string num = this.txtNum.Text;
            string author = this.txtAuthor.Text;
            string introduce = this.txtIntroduce.Text;
            //2、sql命令
            string sql = $"insert into y_Books values('{name}','{num}','{author}','{introduce}')";
            try
            {
                //调用dbhelper中的方法
                bool boo = dbHelper.ExecuteNonQuery(sql);
                if (boo)
                {
                    MessageBox.Show("添加成功！");
                    this.Close();
                    Form1 frm1 = new Form1();
                    frm1.Show();
                }
                else
                {
                    MessageBox.Show("添加失败！");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
    }
}
